package com.apache.flow.core.dao;

import java.util.HashMap;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.apache.core.orm.Page;
import com.apache.core.orm.hibernate.ApacheBaseDao;
import com.apache.flow.core.entity.FlowSys;
import com.apache.flow.vo.FlowSysQvo;
import com.apache.tools.StrUtil;

@Repository
public class FlowSysDao extends ApacheBaseDao<FlowSys, String> {
	/**
	 * 
	 * @param qvo vo对象
	 * @param pageNo 当前页
	 * @param pageSize 每页记录数
	 * @return
	 * @throws UctSysException
	 * <p>@description 根据VO封装的查询条件分页查询系统信息
	 * <p>@version 1.0
	 * <p>@author lvcai
	 * <p>@update 2013-7-29 下午04:35:47
	 */
	public Page<FlowSys> getSysListByQvo(FlowSysQvo qvo, int pageNo, int pageSize) throws Exception {
		Page<FlowSys> page = new Page<FlowSys>();
		page.setPageNo(pageNo);
		page.setPageSize(pageSize);

		StringBuffer sb = new StringBuffer("from FlowSys where 1=1 ");

		/**操作权限条件*/
		String cname = qvo.getSysCname();
		String ename = qvo.getSysEname();

		if (StrUtil.isNotNull(cname)) {
			sb.append(" and sysCname like '%").append(cname).append("%'");
		}
		if (StrUtil.isNotNull(ename)) {
			sb.append(" and sysEname like '%").append(ename).append("%'");
		}

		sb.append(" and sysStatus = 1 order by createTime desc ");
		return this.findPage(page, sb.toString(), new HashMap<String, String>());
	}

	/**
	 * 
	 * @return
	 * @throws UctSysException
	 * <p>@description 获取状态为可用的系统信息
	 * <p>@version 1.0
	 * <p>@author lvcai
	 * <p>@update 2013-7-29 下午04:36:43
	 */
	public List<FlowSys> getAllFlowSys() throws Exception {
		String hql = "from FlowSys where 1=1 and sysStatus='1' order by createTime desc ";
		return this.find(hql, new HashMap<String, String>());
	}
}
